from machine import Pin, I2C
import ssd1306

# 初始化 I2C（根据实际硬件调整引脚号）
i2c = I2C(0, scl=Pin(22), sda=Pin(21))  # SCL 接 GPIO22，SDA 接 GPIO21

devices = i2c.scan()

if devices:
    print("I2C devices found:", [hex(d) for d in devices])
    # 初始化 OLED 显示屏
    oled = ssd1306.SSD1306_I2C(128, 64, i2c)  # 宽 128px，高 64px，I2C 地址默认为 0x3C
    # 清屏并显示文字
    oled.fill(0)  # 清空屏幕
    oled.text("Hello, World!", 0, 0)  # 左上角显示文字
    oled.text("MicroPython", 0, 10)
    oled.text("OLED Test", 0, 20)
    oled.show()  # 刷新屏幕
else:
    print("No I2C devices found")

